package models

import (
	"database/sql"

	_ "github.com/go-sql-driver/mysql"
)

/*
智慧教室参观记录  ，对应表wwfw_gddj
*/
func init() {
	//init
}

func (this *Sut_zhjscgjl) Add() (id int, err error) {
	var (
		sqlstr string
		result sql.Result
		lastid int64
	)
	sqlstr = "insert zhjskcb set riqi=?,xxmc=?,lxr=?,tel=?,rs=?,zhiw=?,xxjdr=?,jsr=?"
	result, err = db.Exec(sqlstr, this.Riqi, this.Xxmc, this.Lxr, this.Tel, this.Rs, this.Zhiw, this.Xxjdr, this.Jsr)
	if err != nil {
		return -1, err
	}
	lastid, _ = result.LastInsertId()
	return int(lastid), err
}

func GetZhjsAlls() (rets []Sut_zhjscgjl, err error) {
	var (
		t      Sut_zhjscgjl
		sqlstr string
		rows   *sql.Rows
	)
	sqlstr = "select id,riqi,xxmc,lxr,tel,rs,zhiw,xxjdr,jsr from v_zhjskcb"
	rows, err = db.Query(sqlstr)
	if err != nil {
		return rets, err
	}
	for rows.Next() {
		err = rows.Scan(&t.Id, &t.Riqi, &t.Xxmc, &t.Lxr, &t.Tel, &t.Rs, &t.Zhiw, &t.Xxjdr, &t.Jsr)
		checkErr(err)
		rets = append(rets, t)
	}
	return rets, err
}
